var rand1 = 0;
var rand2 = 0;
var rand3 = 0;
var isClick1 = false;
var isClick2 = false;
var isClick3 = false;
var isDisClick1 = false;
var isDisClick2 = false;
var isDisClick3 = false;
var isClickE1 = true;
var isClickE2 = true;
var isClickE3 = true;
var isDisClickE1 = true;
var isDisClickE2 = true;
var isDisClickE3 = true;

var randDaf = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var butIsLikeDaf = [false, false, false, false, false, false, false,false, false, false];
var butIsDisLikeDaf = [false, false, false, false, false, false, false,false, false, false];

// Fungsi Navigas
function gotoDaftarKonten() {
	document.location.href = "dafkonten.html";
}

function gotoHalamanUtama(){
	document.location.href = "index.html";
}

function gotoHalamanRegistrasi(){
	document.location.href = "reg.html";
}

function gotoHalamanPost() {
	document.location.href = "post.html";
}

function changeStyle(a){
	document.getElementById("style").href=a;
}

function random(a) {
	if (a == 1) {
		rand1 = Math.floor(Math.random()*40001) + 10000;
	} else if (a == 2) {
		rand2 = Math.floor(Math.random()*40001) + 10000;
	} else if (a == 3) {
		rand3 = Math.floor(Math.random()*40001) + 10000;
	}
}

function like(a) {
	if (a == 1) {
		if (!isClick1) {
			if (isDisClick1) {
				rand1++;
				isDisClick1 = false;
			}
			rand1++;
			document.getElementById("p1").innerHTML="Likes = " + rand1;
			isClick1 = true;
			document.getElementById("dislike1").style.backgroundColor = "white";
		} else {
			rand1--;
			document.getElementById("p1").innerHTML="Likes = " + rand1;
			isClick1 = false;
		}
	} else if (a == 2) {
		if (!isClick2) {
			if (isDisClick2) {
				rand2++;
				isDisClick2 = false;
			}
			rand2++;
			document.getElementById("p2").innerHTML="Likes = " + rand2;
			isClick2 = true;
			document.getElementById("dislike2").style.backgroundColor = "white";
		} else {
			rand2--;
			document.getElementById("p2").innerHTML="Likes = " + rand2;
			isClick2 = false;
		}
	} else if (a == 3) {
		if (!isClick3) {
			if (isDisClick3) {
				rand3++;
				isDisClick3 = false;
			}
			rand3++;
			document.getElementById("p3").innerHTML="Likes = " + rand3;
			isClick3 = true;
			document.getElementById("dislike3").style.backgroundColor = "white";
		} else {
			rand3--;
			document.getElementById("p3").innerHTML="Likes = " + rand3;
			isClick3 = false;
		}
	}
}

function dislike(a) {
	if (a == 1) {
		if (!isDisClick1) {
			if (isClick1) {
				rand1--;
				isClick1 = false;
			}
			rand1--;
			document.getElementById("p1").innerHTML="Likes = " + rand1;
			isDisClick1 = true;
			document.getElementById("like1").style.backgroundColor = "white";
		} else {
			rand1++;
			document.getElementById("p1").innerHTML="Likes = " + rand1;
			isDisClick1 = false;
		}
	} else if (a == 2) {
		if (!isDisClick2) {
			if (isClick2) {
				rand2--;
				isClick2 = false;
			}
			rand2--;
			document.getElementById("p2").innerHTML="Likes = " + rand2;
			isDisClick2 = true;
			document.getElementById("like2").style.backgroundColor = "white";
		} else {
			rand2++;
			document.getElementById("p2").innerHTML="Likes = " + rand2;
			isDisClick2 = false;
		}
	} else if (a == 3) {
		if (!isDisClick3) {
			if (isClick3) {
				rand3--;
				isClick3 = false;
			}
			rand3--;
			document.getElementById("p3").innerHTML="Likes = " + rand3;
			isDisClick3 = true;
			document.getElementById("like3").style.backgroundColor = "white";
		} else {
			rand3++;
			document.getElementById("p3").innerHTML="Likes = " + rand3;
			isDisClick3 = false;
		}
	}
}

function mouseOutLike(a) {
	if (a == 1) {
		if (!isClick1) {
			document.getElementById("like1").style.backgroundColor = "white";
		} else {
			document.getElementById("like1").style.backgroundColor = "yellow";
		}
	} else if (a == 2) {
		if (!isClick2) {
			document.getElementById("like2").style.backgroundColor = "white";
		} else {
			document.getElementById("like2").style.backgroundColor = "yellow";
		}
	} else if (a == 3) {
		if (!isClick3) {
			document.getElementById("like3").style.backgroundColor = "white";
		} else {
			document.getElementById("like3").style.backgroundColor = "yellow";
		}
	}
}

function mouseOutDislike(a) {
	if (a == 1) {
		if (!isDisClick1) {
			document.getElementById("dislike1").style.backgroundColor = "white";
		} else {
			document.getElementById("dislike1").style.backgroundColor = "black";
		}
	} else if (a == 2) {
		if (!isDisClick2) {
			document.getElementById("dislike2").style.backgroundColor = "white";
		} else {
			document.getElementById("dislike2").style.backgroundColor = "black";
		}
	} else if (a == 3) {
		if (!isDisClick3) {
			document.getElementById("dislike3").style.backgroundColor = "white";
		} else {
			document.getElementById("dislike3").style.backgroundColor = "black";
		}
	}
}

//fungsi-fungsi untuk dafkonten.html

function randomDaf(a) {
	rand1 = Math.floor(Math.random()*40001);
	if (rand1 % 2 === 0) {
		randDaf[a-1] = Math.floor(Math.random()*50001) * -1;
	} else {
		randDaf[a-1] = Math.floor(Math.random()*50001);
	}
}

function likeDaf(a) {
	if (!butIsLikeDaf[a-1]) {
		if (butIsDisLikeDaf[a-1]) {
			randDaf[a-1]++;
			butIsDisLikeDaf[a-1] = false;
		}
		randDaf[a-1] = randDaf[a-1]+1;
		document.getElementById("p"+a).innerHTML="Likes = " + randDaf[a-1];
		butIsLikeDaf[a-1] = true;
		document.getElementById("dislike"+a).style.backgroundColor="white";
	} else {
		randDaf[a-1]--;
		document.getElementById("p"+a).innerHTML="Likes = " + randDaf[a-1];
		butIsLikeDaf[a-1] = false;
		document.getElementById("dislike"+a).disabled="";
	}
}

function dislikeDaf(a) {
	if (!butIsDisLikeDaf[a-1]) {
		if (butIsLikeDaf[a-1]) {
			randDaf[a-1]--;
			butIsLikeDaf[a-1] = false;
		}
		randDaf[a-1] = randDaf[a-1]-1;
		document.getElementById("p"+a).innerHTML="Likes = " + randDaf[a-1];
		butIsDisLikeDaf[a-1] = true;
		document.getElementById("like"+a).style.backgroundColor="white";
	} else {
		randDaf[a-1]++;
		document.getElementById("p"+a).innerHTML="Likes = " + randDaf[a-1];
		butIsDisLikeDaf[a-1] = false;
	}
}

function mouseOutLikeDaf(a) {
	if (!butIsLikeDaf[a-1]) {
		document.getElementById("like"+a).style.backgroundColor = "white";
	} else {
		document.getElementById("like"+a).style.backgroundColor = "yellow";
	}
}

function mouseOutDisLikeDaf(a) {
	if (!butIsDisLikeDaf[a-1]) {
		document.getElementById("dislike"+a).style.backgroundColor = "white";
	} else {
		document.getElementById("dislike"+a).style.backgroundColor = "black";
	}
}

/*** function untuk add comment *****/

var height = 800;

function setBodyHeight() {
	var doc = document.getElementById("komen");
	height= 950 + doc.clientHeight;
	document.getElementById("body").style.height = height+"px";
}

function addComment() {
	var newItem = document.createElement("div");
	newItem.setAttribute("class", "text");
	var h4Node = document.createElement("h4");
	h4Node.innerHTML = document.getElementById("text_com").value;
	newItem.appendChild(h4Node);
	
	
	var newUser = document.createElement("div");
	newUser.setAttribute("class", "user");
	var pNode = document.createElement("p");
	var date = new Date();
	pNode.innerHTML = "Commented by Anonymous at " + date.getDate() + "/" + (date.getMonth()+1) + "/" + (date.getFullYear() % (Math.round(date.getFullYear()/100)*100)) + " " + date.getHours() + ":" + date.getMinutes();
	newUser.appendChild(pNode);
	
	
	var newHR = document.createElement("div");
	newHR.setAttribute("class", "garis");
	var hrNode = document.createElement("hr");
	newHR.appendChild(hrNode);
	
	var doc = document.getElementById("komen");
	doc.insertBefore(newHR,doc.childNodes[0]);
	doc.insertBefore(newUser,doc.childNodes[0]);
	doc.insertBefore(newItem,doc.childNodes[0]);
	
	setBodyHeight();
}